<template>
  <!-- 排序区域 -->
  <div class="sub-sort">
    <div class="sort">
      <a
        v-for="sort in sortList"
        @click="setSort(sort.id)"
        :key="sort.id"
        :class="{ active: currSelectedId === sort.id }"
        href="javascript:;"
        >{{ sort.name }}</a
      >
      <!-- <a class="active" href="javascript:;">最新商品</a>
      <a href="javascript:;">最高人气</a>
      <a href="javascript:;">评论最多</a> -->
    </div>
  </div>
</template>
<script>
import { inject, ref } from 'vue'
export default {
  name: 'SubSort',
  setup () {
    // 设计数据结构 =>null (默认排序) publishTime(最新)，orderNum(人气)， evaluateNum(评论)
    const sortList = ref([
      { id: null, name: '默认排序' },
      { id: 'publishTime', name: '最新商品' },
      { id: 'orderNum', name: '最高人气' },
      { id: 'evaluateNum', name: '评论最多' }

    ])
    // 当前选中的排序条件的ID
    const currSelectedId = ref(null)
    // 接收过滤条件数据
    const filterParams = inject('filterParams')
    // 点击选中
    const setSort = (currId) => {
      // 如果已经选中 就return
      if (currSelectedId.value === currId) return
      // 存储当前选择的条件=>目的=》发请求刷新列表
      filterParams.value.sortField = currId
      currSelectedId.value = currId
    }
    return { sortList, currSelectedId, setSort }
  }
}
</script>
<style scoped lang='less'>
.sub-sort {
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .sort {
    display: flex;
    a {
      height: 30px;
      line-height: 28px;
      border: 1px solid #e4e4e4;
      padding: 0 20px;
      margin-right: 20px;
      color: #999;
      border-radius: 2px;
      position: relative;
      transition: all 0.3s;
      // 选中高亮
      &.active {
        background: @xtxColor;
        border-color: @xtxColor;
        color: #fff;
      }
      .arrow {
        position: absolute;
        border: 5px solid transparent;
        right: 8px;
        &.up {
          top: 3px;
          border-bottom-color: #bbb;
          &.active {
            border-bottom-color: @xtxColor;
          }
        }
        &.down {
          top: 15px;
          border-top-color: #bbb;
          &.active {
            border-top-color: @xtxColor;
          }
        }
      }
    }
  }
  .check {
    .xtx-checkbox {
      margin-left: 20px;
      color: #999;
    }
  }
}
.list-container {
  margin-top: 20px;
  padding: 0 20px;
  background: #fff;
}
</style>
